﻿namespace Microsoft.SharePoint.Client.WebParts
{
    using Microsoft.SharePoint.Client;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;

    [ScriptType("SP.WebParts.WebPartDefinitionCollection", ServerTypeId="{01c986b2-57a6-49fb-b8f1-df159f5b2349}")]
    public class WebPartDefinitionCollection : ClientObjectCollection<WebPartDefinition>
    {
        [EditorBrowsable(EditorBrowsableState.Never)]
        public WebPartDefinitionCollection(ClientRuntimeContext Context, ObjectPath ObjectPath) : base(Context, ObjectPath)
        {
        }

        [Remote]
        public WebPartDefinition GetById(Guid id)
        {
            Dictionary<Guid, WebPartDefinition> dictionary;
            object obj2;
            if (base.ObjectData.MethodReturnObjects.TryGetValue("GetById", out obj2))
            {
                dictionary = (Dictionary<Guid, WebPartDefinition>) obj2;
            }
            else
            {
                dictionary = new Dictionary<Guid, WebPartDefinition>();
                base.ObjectData.MethodReturnObjects["GetById"] = dictionary;
            }
            WebPartDefinition definition = null;
            if (!dictionary.TryGetValue(id, out definition))
            {
                definition = new WebPartDefinition(base.Context, new ObjectPathMethod(base.Context, base.Path, "GetById", new object[] { id }));
                dictionary[id] = definition;
            }
            return definition;
        }

        protected override bool InitOnePropertyFromJson(string peekedName, JsonReader reader)
        {
            bool flag = base.InitOnePropertyFromJson(peekedName, reader);
            if (flag)
            {
                return flag;
            }
            return flag;
        }
    }
}

